import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class Custom_iOS_Dialog {
  ///苹果风格的提示框
  static void info(BuildContext context,
      {@required String content,
      String title: "提示",
      String okLabel: "确定",
      bool barrierDismissible: false,
      Function okFn,
      Function cancelFn}) {
    var dialog = CupertinoAlertDialog(
      title: Text(
        title,
        style: TextStyle(fontSize: 18),
      ),
      content: Text(
        content,
        style: TextStyle(fontSize: 16),
      ),
      actions: <Widget>[
        CupertinoButton(
          child: Text(okLabel),
          onPressed: () {
            Navigator.pop(context);
            okFn();
          },
        ),
      ],
    );

    showDialog(context: context, builder: (_) => dialog);
  }

  ///苹果风格的提示框
  static void prompt(BuildContext context,
      {@required String content,
      String title: "提示",
      String okLabel: "确定",
      String cancelLabel: "取消",
      bool barrierDismissible: false,
      Function okFn,
      Function cancelFn}) {
    var dialog = CupertinoAlertDialog(
      title: Text(
        title,
        style: TextStyle(fontSize: 18),
      ),
      content: Column(
        children: <Widget>[
          SizedBox(height: 10),
          Text(
            content,
            style: TextStyle(fontSize: 16),
          )
        ],
      ),
      actions: <Widget>[
        CupertinoButton(
          child: Text(cancelLabel),
          onPressed: () {
            Navigator.pop(context);
            cancelFn();
          },
        ),
        CupertinoButton(
          child: Text(okLabel),
          onPressed: () {
            Navigator.pop(context);
            okFn();
          },
        ),
      ],
    );

    showDialog(context: context, builder: (_) => dialog);
  }

  /// warn
  static void warn(BuildContext context,
      {@required String content,
      String title: "警告",
      bool barrierDismissible: false,
      String okLabel: "确定"}) {
    var dialog = CupertinoAlertDialog(
      title: Text(
        title,
        style: TextStyle(fontSize: 18),
      ),
      content: Text(
        content,
        style: TextStyle(fontSize: 16, color: Colors.yellow),
      ),
      actions: <Widget>[
        CupertinoButton(
          child: Text("取消"),
          onPressed: () {
            Navigator.pop(context);
          },
        ),
        CupertinoButton(
          child: Text(okLabel),
          onPressed: () {
            Navigator.pop(context);
          },
        ),
      ],
    );

    showDialog(context: context, builder: (_) => dialog);
  }

  /// error
  static void error(BuildContext context,
      {@required String content,
      String title: "错误",
      bool barrierDismissible: false,
      String okLabel: "确定"}) {
    var dialog = CupertinoAlertDialog(
      title: Text(
        title,
        style: TextStyle(fontSize: 18),
      ),
      content: Text(
        content,
        style: TextStyle(fontSize: 16, color: Colors.red),
      ),
      actions: <Widget>[
        CupertinoButton(
          child: Text("取消"),
          onPressed: () {
            Navigator.pop(context);
          },
        ),
        CupertinoButton(
          child: Text(okLabel),
          onPressed: () {
            Navigator.pop(context);
          },
        ),
      ],
    );

    showDialog(context: context, builder: (_) => dialog);
  }
}
